package com.sinux.mms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinux.mms.dao.MemberDaoI;
import com.sinux.mms.entity.Member;
import com.sinux.mms.service.MemberServiceI;
import com.sinux.mms.util.DateTools;

/**
 * @author WangGan
 * @version 2017年6月14日 上午11:51:12 
 * 
 */
@Service
public class MemberServiceImpl implements MemberServiceI {
	
	@Autowired
	private MemberDaoI memberDao;

	@Override
	public List<Member> findAllMemberList() {
		String hql="from Member m where m.state=1";
		List<Member> members=memberDao.find(hql);
		return members;
	}

	@Override
	public List<Member> findMemberPageing(int page, int rows) {
		String hql="from Member m where m.state=1";
		List<Member> members=memberDao.find(hql, page, rows);
		return members;
	}

	@Override
	public List<Member> findMemberList(String value) {
		String hql="from Member m where m.state=1 and (m.id like '%"+value+"%' or m.name like '%"+value+"%' or m.phone like '%"+value+"%') ";
		List<Member> members=memberDao.find(hql);
		return members;
	}

	@Override
	public void addMember(Member member) {
		member.setCdate(DateTools.getCurrentTime());
		memberDao.save(member);
		
	}

	@Override
	public void upState(String id, int state) {
		String hql="update Member m set m.state=:state where m.id=:id  ";
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("state", state);
		params.put("id", id);
		memberDao.update(hql, params);
		
	}

	@Override
	public void upMember(Member member) {
		// TODO Auto-generated method stub
		memberDao.save(member);
	}

}
